/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.anism.API;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.anism.entity.Employee;

/**
 *
 * @author user
 */
@Stateless
public class Authentication implements AuthenticationLocal {

    @PersistenceContext(unitName = "Holidays2-ejbPU")
    private EntityManager em;

    @Override
    public Employee authenticate(String login, String pass) {
        Query q = em.createNamedQuery("Employee.findByEmployeeId").setParameter("employeeId", login);
        try {
            Employee e = (Employee) q.getSingleResult();
            
            if (e != null && e.getPassword().equals(pass)) {
                return e;
            } else {
                return null;
            }
        } catch (Exception e) {
            return null;
        }
    }
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
}
